package com.bwie.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bwie.pojo.TbBrand;
import com.bwie.service.TbBrandService;
import com.bwie.mapper.TbBrandMapper;
import com.bwie.utils.Result;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

/**
* @author wx200
* @description 针对表【tb_brand(品牌表)】的数据库操作Service实现
* @createDate 2025-05-23 15:30:42
*/
@Service
public class TbBrandServiceImpl extends ServiceImpl<TbBrandMapper, TbBrand>
    implements TbBrandService{
@Autowired
TbBrandMapper tbBrandMapper;


@Autowired
    HttpServletRequest request;
    @Override
    public Result updateBrandStatus(TbBrand tbBrand) {
//        获取品牌信息
        TbBrand brand = tbBrandMapper.selectById(tbBrand.getBrandId());
       if(brand==null){
           return Result.error().setMsg("品牌不存在");
       }
//     跟新品牌状态
        brand.setBrandStatus(tbBrand.getBrandStatus());
        Claims body = Jwts.parser().setSigningKey("123456").parseClaimsJws(request.getHeader("token")).getBody();
        String nickName = body.get("nickName", String.class);
        brand.setUpdateTime(new Date());
        brand.setUpdateBy(nickName);
         tbBrandMapper.updateById(brand);
        return Result.ok();
    }

    @Override
    public Result getBrandListAll() {
        List<TbBrand> tbBrands = tbBrandMapper.selectList(null);
        return Result.ok().setData(tbBrands);
    }

}




